package org.regotto.basics.dfs;

/**
 * 数字全排列
 */
public class FullArrayOfNumbers {

    //1, 2, 3, 4 做全排列
    static int n = 4;
    static int[] p = new int[10], st = new int[10];

    static void dfs(int u) {
        if (u == n) {
            for (int i = 0; i < n; i++) {
                System.out.print(p[i] + " ");
            }
            System.out.println();
            return;
        }
        for (int i = 1; i <= n; i++) {
            if (st[i] == 0) {
                p[u] = i;
                st[i] = 1;
                dfs(u + 1);
                st[i] = 0;
            }
        }
    }

    public static void main(String[] args) {
        dfs(0);
    }

}
